<template>
	<view class="address">
		<scroll-view scroll-y class="address-list" v-if="addressList.length">
			<view class="address-item" v-for="(data,index) in addressList" :key="index">
				<view class="address-item-left">
					<view class="address-item-hd">
						<text>{{data.consignee}}</text>
						<text>{{data.mobile}}</text>
					</view>
					<view class="address-item-bd">
						<text v-if="data.province">{{data.province}}</text>
						<text v-if="data.city">{{data.city}}</text>
						<text v-if="data.district">{{data.district}}</text>
						{{data.address}}
					</view>
				</view>
				<view class="address-item-right" @click="edit(data)">编辑</view>
			</view>
		</scroll-view>
		<nothing :text="'还未添加地址'" @goUrl="edit()" :btnTxt="'去添加地址'" v-else></nothing>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressList: []
			};
		},
		onLoad() {
			
		},
		onShow() {
			this.init()
		},
		methods: {
			init(){
				this.$api.AddressList({type: 2}).then(res => {
					this.addressList = res.datas
				})
			},
			edit(data){
				if(data){
					uni.navigateTo({
						url: '/pages/my/address/address-info?data='+JSON.stringify(data)
					})
				}else{
					uni.navigateTo({
						url: '/pages/my/address/address-info'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.address{
		.address-list{
			position: fixed;
			top: 20rpx;
			left: 0;
			right: 0;
			bottom: 0;
			.address-item{
				background-color: #FFF;
				display: flex;
				padding: 40rpx 20rpx;
				align-items: center;
				font-size: 28rpx;
				border-bottom: solid 1px #EEE;
				.address-item-left{
					flex: 1;
					min-width: 0;
					margin-right: 40rpx;
					.address-item-hd{
						font-size: 32rpx;
						margin-bottom: 20rpx;
						text{
							margin-right: 30rpx;
							&:last-child{
								margin-right: 0;
							}
							&.default{
								padding: 0 20rpx;
								color: #FFF;
								font-size: 24rpx;
								border-radius: 10rpx;
								display: inline-block;
								vertical-align: middle;
								background-image: linear-gradient(to right,#ff9958,#ff4544);
								margin-top: -8rpx;
								height: 38rpx;
								line-height: 38rpx;
							}
						}
					}
					.address-item-bd{
						color: #666;
						line-height: 42rpx;
					}
				}
				.address-item-right{
					color: #2073F5;
				}
			}
		}
		.address-btn{
			position: fixed;
			bottom: 60rpx;
			left: 75rpx;
			right: 75rpx;
			button{
				height: 100rpx;
				line-height: 100rpx;
				background-color: #2073F5;
				border-radius: 100rpx;
				color: #FFF;
				font-size: 36rpx;
			}
		}
	}
</style>
